package com.endava.nio_io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;

public class Io_RandomAccessFile {
	public static void main(String[] args) throws IOException {
		File f=new File("file.txt");
		RandomAccessFile raf=new RandomAccessFile(f, "rw");
		
		raf.seek(0);//seek start of file
		double d=raf.readDouble();//read double value
		System.out.println(d);
		
		raf.seek(f.length()/2);//seek to middle of file
		char ch=raf.readChar();//read character
		System.out.println(ch);
		
		raf.seek(f.length());//seek end of file
		raf.writeChars("howdy");//append "howdy" to end of file
		
		FileReader fileReader = new FileReader("file.txt");
		@SuppressWarnings("resource")
		BufferedReader bufReader = new BufferedReader(fileReader);
		@SuppressWarnings("unused")
		int value=0;
		while ((value = bufReader.read()) != -1) {
			System.out.println(bufReader.readLine());

		}
		
		raf.close();
	}
}
